package com.uestc.soft.service;

import com.uestc.soft.mapper.LogMapper;
import com.uestc.soft.pojo.Log;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogService {

    @Resource
    private LogMapper logMapper;

    public Map<String, Object> selectByPage(int page, int limit, String level, String event, String host, String state, String deal) {
        // page 页码   (page-1)*limit=起始下标index
        int index = (page - 1) * limit;   // 计算出起始下标
        List<Log> userList = logMapper.selectByLogPage(index, limit, level, event, host, state, deal);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", logMapper.selectLogCount(level, event, host, state, deal));
        map.put("data", userList);
        return map;
    }

    public Map<String, Object> insertLog(Log log) {
        logMapper.insertLog(log);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增用户成功");
        return map;
    }

    public Map<String, Object> deleteByLogId(Integer id) {
        logMapper.deleteByLogId(id);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "删除用户成功");
        return map;
    }

    public Map<String, Object> updateDeal(Integer id, String deal) {
        logMapper.updateDeal(id, deal);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "更新用户成功");
        return map;
    }
}
